package hacker_rank.mar14;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

public class ManasaMaths {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		Set<String> multiples_3 = new TreeSet<String>();
		for (int i = 13; i < 125; i++) {
			char[] ca = String.format("%03d", 8 * i).toCharArray();
			Arrays.sort(ca);
			multiples_3.add(String.valueOf(ca));

		}

		Set<String> multiples_2 = new TreeSet<String>();
		for (int i = 0; i <= 12; i++) {
			char[] ca = String.format("%02d", 8 * i).toCharArray();
			Arrays.sort(ca);

			multiples_2.add(String.valueOf(ca));
		}

		/*
		 * for(String s: multiples_3) { System.out.println("Sort: " + s); }
		 */

		int T = Integer.parseInt(br.readLine());
		for (int t = 0; t < T; t++) {
			String line = br.readLine();
			if (line.length() == 1) {
				Integer in = Integer.parseInt(line);
				if (in % 8 == 0)
					System.out.println("YES");
				else
					System.out.println("NO");

			} else if (line.length() == 2) {
				solve2(line, multiples_2);

			} else {
				solve(line, multiples_3);
			}
		}
	}

	static void solve(String line, Set<String> mult_set) {
		char[] ca = line.toCharArray();

		

		for (String mul : mult_set) {
			Map<Character, Integer> patMap = new HashMap<Character, Integer>();
			for (Character c : mul.toCharArray()) {
				Integer cnt = patMap.get(c);
				if (cnt == null)
					cnt = 0;
				patMap.put(c, cnt + 1);
			}

			for (Character c : ca) {
				Integer cnt = patMap.get(c);
				if (cnt != null && cnt <= 1)
					patMap.remove(c);
				else if (cnt != null)
					patMap.put(c, cnt - 1);
			}

			if (patMap.isEmpty()) {
				System.out.println("YES");
				return;
			}

		}
		System.out.println("NO");

	}

	static void solve2(String line, Set<String> mult_set) {
		char[] ca = line.toCharArray();
		Arrays.sort(ca);
		line = String.valueOf(ca);

		for (String mul : mult_set) {
			if (line.indexOf(mul) >= 0) {
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");

	}
}
